//
//  BFStatusView.m
//  13KModel
//
//  Created by ISS on 9/09/12.
//  Copyright (c) 2012 __butterfly__. All rights reserved.
//
// SYSTEM INCLUDES
#import "BFStatusView.h"

// CLASS INCLUDES
#import <QuartzCore/QuartzCore.h>

// CONST DEFINE
CGFloat const kBorderWidth = 2.0f;
CGFloat const kBorderRadius = 5.0f;

@interface BFStatusView ()

@end

@implementation BFStatusView
@synthesize imageView, activityView;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 视图修饰
        self.clipsToBounds = YES;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.layer.borderWidth = kBorderWidth;
        self.layer.cornerRadius = kBorderRadius;
        
        // 创建背景图
        imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:imageView];

        // 创建LOADING效果
        activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
		[self addSubview:activityView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    activityView.frame = CGRectMake(self.bounds.size.width/2-10.0f,
                                    self.bounds.size.height/2-10.0f,
                                    20.0f,
                                    20.0f);
    imageView.frame = self.bounds;
}

- (void)startLoading
{
    if (activityView.isAnimating) {
        return;
    }
    
    [activityView startAnimating];
}

- (void)stopLoaidng
{
    if (!activityView.isAnimating) {
        return;
    }
    
    [activityView stopAnimating];
}

@end
